package com.aspirecn.auth.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aspirecn.auth.common.RestApiResponseHandler;
import com.aspirecn.auth.domain.vo.ResponseHead;
import com.aspirecn.auth.domain.vo.ResponseMsg;

@FrameworkEndpoint
public class RevokeTokenEndpoint {
	private static final Logger LOG = LoggerFactory.getLogger(RevokeTokenEndpoint.class);
	@Autowired
	@Qualifier("consumerTokenServices")
	ConsumerTokenServices consumerTokenServices;

	@RequestMapping(method = RequestMethod.GET, value = "/oauth/revokeToken")
	@ResponseBody
	public ResponseMsg<?> revokeToken(String access_token) {
		LOG.info("test1111111111111111");
		ResponseHead responseHead = new ResponseHead();
		if (consumerTokenServices.revokeToken(access_token)) {
			return RestApiResponseHandler.successResponseMsg(responseHead, "注销成功");
		} else {
			return RestApiResponseHandler.errorResponseMsg(responseHead, "注销失败");
		}
	}
}
